Eftekhari m
Test Methods Prepared by : marzieh eftekhari Test Methods ''' ''Composition and Execution of Test Methods'' ' The smallest groupings of test expressions are the methods that you put them in. Whether you use JUnit or not, you need to put your test expressions into Java methods, so you might as well group the expressions, according to any criteria you want, into methods. If you designate such a test method with the "@org.junit.Test" annotation, then JUnit will execute it as explained in the Test Classes and the JUnit Test Execution Environment chapter (and that is the ultimate purpose of doing so). For this document, I call such a method a ''test method. The general recommendation is to test only one aspect of behavior in a method. (I know how vague this is). If that can be done with a single expression, then your test method should contain just one expression. There are two main reasons for keeping test methods very fine-grained. First, your report output is only as granular as the test methods. If you have 10 methods each of which tests handling of a different type of input character, your test report will have a count (at least) for the success or failure of each character type. If you put the expressions to test all ten character types into a single test method, you will only get a single test result for all character types. The difference is drastic. If your first test fails, none of the other tests will even execute in the single-method scenario. Secondly, setup and execution of one test may cause unintended consequences for a test which follows. This risk is usually acceptable for a single-author class, but for jointly developed software, or test classes which will outlast the tenure of the original author, the risk can be considerable. There are several important observations to be made here. It must be an instance method of type void with no parameters.the name of the method doesn't matter test-runners (or to anything else). So, you can implement your own method naming convention. I didn't prefix the method name with "test" to comply with any JUnit rule, but because it makes the methods easy to recognize (both for human readers, and for scripts, Ant build files, etc.). Your test methods are allowed to throw anything by the rules of JUnit, but a good test method won't declare any Throwables (more on this topic below). Test methods are single-threaded, but different test methods must be independent and can't depend on state (including values of instance or static variables) set by another test method. If you are going to make use of instance variables, you must take pains to initialize the variable values for each test method run. The following chapter explains how the test-runners set up and execute your test methods, and how you can write shared setup and shut down code. If your test method calls other methods which declare checked exceptions, you should not just declare it in your test method, but should handle it in either normal Java try/catch fashion, or with the JUnit expected attribute. If you have elicited a Throwable on purpose, you can catch it to detect that, but if your test method is fine-grained (as it should be), you can accomplish the same thing more gracefully by telling JUnit that your test method should throw the specified Throwable. In this example, we assume the source file has an import statement for java.io.IOException. If, on the other hand, production of the Throwable indicates a test failure, then you should catch it from a try block and fail the test with something like Assert.fail(String). Here is a code snippet that handles the very common case where the code being tested could throw any of various Exceptions, and they should all be considered test failures, not an error in the test system. This idiom can save you a lot of work and still create well-behaved tests. A test method is a definitive procedure that produces a test result. A test can be considered as technical operation that consists of determination of one or more characteristics of a given product, process or service according to a specified procedure. Often a test is part of an experiment. The test result can be qualitative (yes/no), categorical, or quantitative (a measured value). It can be a personal observation or the output of a precision measuring instrument. Usually the test result is the dependent variable, the measured response based on the particular conditions of the test or the level of the independent variable. Some tests, however, may involve changing the independent variable to determine the level at which a certain response occurs: in this case, the test result is the indeIn software development, engineering, science, manufacturing, and business, it is vital for all interested people to understand and agree upon methods of obtaining data and making measurements. It is common for a physical property to be strongly affected by the precise method of testing or measuring that property. It is vital to fully document experiments and measurements and to provide needed definitions to specifications and contracts. Using a standard test method, perhaps published by a respected standards organization, is a good place to start. Sometimes it is more useful to modify an existing test method or to develop a new one. Again, documentation and full disclosure are very necessary. A well-written test method is important. However, even more important is choosing a method of measuring the correct property or characteristic. Not all tests and measurements are equally useful: usually a test result is used to predict or imply suitability for a certain purpose. For example, if a manufactured item has several components, test methods may have several levels of connections: *test results of a raw material should connect with tests of a component made from that material *test results of a component should connect with performance testing of a complete item *results of laboratory performance testing should connect with field performance These connections or correlations may be based on published literature, engineering studies, or formal programs such as quality function deployment. Validation of the suitability of the test method is often required. Content of a test method Quality management systems usually require full documentation of the procedures used in a test. The document for a test method might include: *Descriptive title *Scope over which class(es) of materials or articles may be evaluated *Date of last effective revision and revision designation *Reference to most recent test method validation *Person, office, or agency responsible for questions on the test method, updates, and deviations. *The significance or importance of the test method and its intended use. *Terminology and definitions to clarify the meanings of the test method *A listing of the types of apparatus and measuring instrument (sometimes the specific device) required to conduct the test *Safety precautions *Required calibrations and metrology systems *Environmental concerns and considerations *Sampling procedures: How samples are to be obtained, and Number of samples (sample size). *Conditioning or required environmental chamber: temperature, humidity, etc., including tolerances *Preparation of samples for the test and test fixtures *Detailed procedure for conducting the test *Calculations and analysis of data *Interpretation of data and test method output *Report: format, content, data, etc =Design of experiments = Design of experiments with full factorial design (left), response surface with second-degree polynomial (right) In general usage, design of experiments (DOE) or experimental design is the design of any information-gathering exercises where variation is present, whether under the full control of the experimenter or not. However, in statistics, these terms are usually used for controlled experiments. Formal planned experimentation is often used in evaluating physical objects, chemical formulations, structures, components, and materials. Other types of study, and their design, are discussed in the articles on opinion polls and statistical surveys (which are types of observational study), natural experiments and quasi-experiments (for example, quasi-experimental design). See Experiment for the distinction between these types of experiments or studies. In the design of experiments, the experimenter is often interested in the effect of some process or intervention (the "treatment") on some objects (the "experimental units"), which may be people, parts of people, groups of people, plants, animals, etc. Design of experiments is thus a discipline that has very broad application across all the natural and social sciences and engineering . References 1. ^ Form and Style Manual, ASTM, http://www.astm.org/COMMIT/Blue_Book.pdf, 2009 2. ^ ASTM E 1301, Standard Guide for Proficiency Testing by Interlaboratory Comparisons General references, Books · Pyzdek, T, "Quality Engineering Handbook", 2003, ISBN 0-8247-4614-7 · Godfrey, A. B., "Juran's Quality Handbook", 1999, ISBN 007034003 · Kimothi, S. K., "The Uncertainty of Measurements: Physical and Chemical Metrology: Impact and Analysis", 2002, ISBN 0-87389-535-5